<?php
    header("Content-type:text/html;charset=utf-8");
    include "Model.php";
    echo "<pre>";
    $conn =new Mysql('preferredshares','oc_user_org');
    $sql ='select uid as client_id ,equity_time as confirm_time,equity,createtime as create_time ,parent_id, m.id as management_id 
    from  oc_user_org as o 
    left join client_management as m on  uid =m.client_id  
    where type =3';
    $res=$conn->getAll($sql);
    //var_dump($res);
    //exit;
    $conn1 =  new Mysql('preferredshares','client_initiator_company');
    $sql ="select id  from oc_user_org  where type in (1,2,3)";
    $ids=$conn->getArr($sql,'id');
    //var_dump($ids);
    //exit;
    
    foreach ($res as $k =>$v){
        $data =array();
        //var_dump($v['parent_id']);
        if(in_array($v['parent_id'],$ids)){
             //var_dump("hello  jiajia***************************************");
            $sql ="select uid from oc_user_org where id= {$v['parent_id']}";
            $ress=$conn->getArr($sql,'uid');
           $newSql="select id from client_initiator_company where client_id ={$ress[0]}";
            $resss=$conn1 ->getArr($newSql,'id');
            var_dump($resss);
            //$data['parent_cid'] =$resss[0];
              
        }else{
          
            var_dump("hello world");
            $data['parent_cid'] ="";
            
        } 
        
        $data['client_id']       =$v['client_id'];
        $data['confirm_time']    =$v['confirm_time']==Null ? Null:date('Y-m-d H:i:s',$v['confirm_time']);
        $data['create_time']     =$v['create_time'] ==0    ? Null:date('Y-m-d H:i:s',$v['create_time']);
        $data['management_id']   =$v['management_id'];
        $data['is_management']   =isset($v['management_id'])?1:0;
        $data['update_time']     ='null';
        $data['is_qualified']    =$v['equity']==Null ? 0 : 1;
        //echo '<pre>';
        //var_dump($data);
        //exit;
        //$res=$conn1->insert($data);
        //var_dump($res);
    } 
    echo '<script>alert("插入数据库成功")</script>';